<?php

    if (!defined('EXPONENT')) exit('');
    if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate"),$loc)){
        $sql_where = 'location_data = \''.serialize($loc).'\' ';
        if(isset($_REQUEST['search_name']))
        {   
            $search_name = ($_REQUEST['search_name']);
            $sql_where.=" AND ((title LIKE '%{$search_name}%') OR (search_des LIKE '%{$search_name}%')) ";
        }
        $page=1;
        if (isset($_REQUEST['page']))
            $page=intval($_REQUEST['page']);
        $pageSize=10;

        if (isset($_REQUEST['rows']))
            $pageSize=intval($_REQUEST['rows']);
        $start=($page-1)*$pageSize;

        $data=$db->selectObjects('videomodule_cat',"{$sql_where} ORDER BY id  LIMIT {$start},{$pageSize}");

        foreach ($data as $k=>$v){
            // split description
            $v->description = substr(strip_tags($v->description),0,200)."...";
            //$v->name = substr(strip_tags($v->name),0,100)."...";
            $v->post_date = strftime(DISPLAY_DATETIME_FORMAT, $v->post_date);
        }

        $ret_object = null;
        $ret_object->total = $db->countObjects('videomodule_cat',"{$sql_where}");
        $ret_object->rows = $data; 
        echo json_encode($ret_object);
    }
    die();
?>
